package routes

import (
	"gitee.com/shijun123456/rpcVotes/internal/config"
	"gitee.com/shijun123456/rpcVotes/internal/services"
	"gitee.com/shijun123456/rpcVotes/internal/svc"
	"gitee.com/shijun123456/srpcinterface/client/votes"
	"github.com/tal-tech/go-zero/zrpc"
	grpc "google.golang.org/grpc"
	"google.golang.org/grpc/keepalive"
	"time"
)

//注册我们的路由服务信息
//配置信息
//上下文信息
func RegisterRoutes(c config.Config, svcCtx *svc.ServiceContext) *zrpc.RpcServer {

	voteSvc := services.NewVotesServer(svcCtx)
	xindaSvc := services.NewXindaluService(svcCtx)

	//这咯可以注册一千个服务 方法 但是都是 属于 user这个命名空间下的服务
	// user/file ->调用 fileSvc
	// user/add ->调用 addSvc方法

	s := zrpc.MustNewServer(c.RpcServerConf, func(grpc_server *grpc.Server) {
		votes.RegisterVotesServer(grpc_server, voteSvc)
		votes.RegisterPaySvcServer(grpc_server, xindaSvc)
	})
	s.AddOptions(grpc.KeepaliveParams(keepalive.ServerParameters{
		MaxConnectionIdle: 5 * time.Minute,
		Timeout:           time.Second * 5,
	}))

	return s
}
